<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common.jspf"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="<%=basePath%>ztree/js/jquery.ztree.excheck.js"></script>
<title></title>
<script type="text/javascript">
	$(function() {
		$("#content").attr("height",
				document.documentElement.clientHeight - 140);

		var setting = {
			async : {
				enable : true,
				url : "user/roles/" + $("#uid").val()
			},
			check : {
				enable : true
			},
			data : {
				simpleData : {
					enable : true,
					idKey : "id",
					pIdKey : "pid",
					rootPId : 0
				}
			}
		}

		$.fn.zTree.init($("#roleTree"), setting);
	})
	function saveRoles() {
		//获取所有被选中的节点
		var treeObj = $.fn.zTree.getZTreeObj("roleTree");
		var nodes = treeObj.getCheckedNodes(true);
		if (nodes.length > 0) {
			var ids = "";
			for ( var i in nodes) {
				ids = ids + "," + nodes[i].id;
			}
			ids = ids.substring(1);
			$.ajax({
				url : "user/setroles",
				data : {
					roleids : ids,
					userid : $("#uid").val()
				},
				dataType : "json",
				type : "post",
				success : function(data) {
					if (data.code == "OK") {
						$.messager.show({
							title : '权限设置',
							msg : data.msg,
							timeout : 1000,
							showType : 'slide'
						});
						setTimeout(function() {
							location = "page/user/list";
						}, 1500);
					} else {
						$.messager.alert("权限设置", data.msg, "info");
					}
				}
			})
		}
	}
</script>
</head>
<body>
	<div style="margin-top: 40px; margin-left: 40px">
		<ul class="ztree" id="roleTree"></ul>
		<input id="uid" type="hidden" name="uid" value="${uid}"> <a
			href="javascript:void(0);" onclick="saveRoles()"
			style="margin-left: 20px" class="easyui-linkbutton"
			data-options="iconCls:'icon-save'">保存角色</a>
	</div>
</body>
</html>